﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<script>
    var n_keyValue; // 桥梁代码
    var n_checkport; // 检查报告
    var n_djprocedirecpmpany; // 检查公司
    var RouteCode1 = "level1";
    $(document).ready(function () {
        // 获取 keyValue
        var keyValue = getQueryParam("keyValue");
        n_keyValue = keyValue;
        var view11 = getQueryParam("view");
        const rawCheckPort = getQueryParam("rawCheckPort");
        n_checkport = rawCheckPort;
        const rawDjProcedureCompany = getQueryParam("rawDjProcedureCompany");
        n_djprocedirecpmpany = rawDjProcedureCompany;
        console.log('子页面BridgeCode', keyValue)
        console.log('子页面rawCheckPort', rawCheckPort)
        console.log('子页面rawDjProcedureCompany', rawDjProcedureCompany)
        if (keyValue) {
            $("#BridgecodeDisplay").text(keyValue);
            $("#F_CreatorTime").val(rawCheckPort);
            $("#F_StartIP").val(rawDjProcedureCompany);
        } else {
            console.error('keyValue 参数未找到！');
            $("#BridgecodeDisplay").text("参数未找到！");
        }
        var urlParams = new URLSearchParams(window.location.search);
        // 根据 'view' 参数的值激活相应的标签页
        if (view11 === 'disease') {
            $('#disease-tab').tab('show');
        } else {
            $('#home-tab').tab('show');
        }

        // 绑定标签页切换事件
        $('#myTab a').on('shown.bs.tab', function (e) {
            var target = $(e.target).attr('href'); // 获取激活的标签页的目标
            if (target === '#home') {
                gridList();
            } else if (target === '#disease') {
                diseaseGridList();
            }
        });
    });

    function getQueryParam(name) {
        const urlParams = new URLSearchParams(window.location.search);
        return urlParams.get(name);
    }

    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "定检记录添加",
            url: "/SystemSecurity/BridgeMange/Form?keyValue=" + n_keyValue, // 正确使用&连接参数
            width: "450px",
            height: "400px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        });
    }

    function btn_disease_add() {
        $.modalOpen({
            id: "DiseaseForm",
            title: "病害录入",
            url: "/SystemSecurity/ServerMonitoring/Form?keyValue=" + n_keyValue, // 正确使用&连接参数
            width: "450px",
            height: "400px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        });
    }

    function gridList() {
        var $gridList = $("#gridList");
        const urlParams = new URLSearchParams(window.location.search);
        const data = urlParams.get('keyValue');
        $gridList.dataGrid({
            url: "/SystemSecurity/BridgeMange/GeBridgeDataCompany?keyValue=" + encodeURIComponent(data),
            colModel: [
                { label: "桥梁名称", name: "Bridgetype", width: 117, key: true },
                { label: '桥梁代码', hidden: true, name: 'Bridgecode', width: 150, align: 'left' },
                {
                    label: '检查日期', name: 'CheckTime', width: 100, align: 'left',
                    formatter: "date", formatoptions: { srcformat: 'Y-m-d ', newformat: 'Y-m-d ' }
                },
                {
                    label: '下次检查日期', name: 'CheckNextTime', width: 100, align: 'left',
                    formatter: "date", formatoptions: { srcformat: 'Y-m-d ', newformat: 'Y-m-d ' }
                },
                { label: '推送状态', name: 'CheckStatus', width: 50, align: 'middle' },
                { label: '定检承担单位', name: 'DjProcedureCompany', width: 150, align: 'middle' },
                { label: '检查报告', name: 'CheckPort', width: 100, align: 'left' },
            ],
        });
    }

    function diseaseGridList() {
        var $gridList = $("#gridList");
        const urlParams = new URLSearchParams(window.location.search);
        const data = urlParams.get('keyValue');
        $gridList.dataGrid({
            url: "/SystemSecurity/BridgeMange/GeDiseaseDataCompany?keyValue=" + encodeURIComponent(data),
            colModel: [
                { label: "桥名称", name: "Bridgetype", width: 117, key: true },
                { label: "桥型", name: "Diseasetype", width: 117, key: true },
                { label: '病害类型', name: 'ImpDiseaseType', width: 150, align: 'left' },
                { label: '病害描述', name: 'DiseaseDescription', width: 150, align: 'left' },
                { label: '病害扣分', name: 'Score', width: 50, align: 'middle' },
                { label: '是否重点病害', name: 'IsDIseaseImp', width: 150, align: 'middle' },
                { label: '重点病害分类', name: 'ImpDiseaseType', width: 100, align: 'left' },
            ],
        });
    }

    var RouteCode = getQueryParam("RouteCode");
    console.log('子页面等级', RouteCode);
</script>

<form id="form1">
    <div style="margin-bottom: 0px; border-radius: 0px;" class="alert alert-warning alert-dismissable">
        <strong>注意：</strong>&nbsp;请准确输入定检或病害信息等字段
    </div>
    <div class="gridPanel">
        <table id="gridList"></table>
    </div>
    <ul class="nav nav-tabs" id="myTab" role="tablist">
        <li class="nav-item">
            <a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">定检记录</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" id="disease-tab" data-toggle="tab" href="#disease" role="tab" aria-controls="disease" aria-selected="false">病害录入</a>
        </li>
    </ul>
    <div class="tab-content" id="myTabContent">
        <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
            <div class="toolbar" style="display: flex; justify-content: center;">
                <div class="btn-group">
                    <a id="NF-add" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_add()">
                        <i class="fa fa-plus"></i>定检记录添加
                    </a>
                </div>
            </div>
        </div>
        <div class="tab-pane fade" id="disease" role="tabpanel" aria-labelledby="disease-tab">
            <div class="toolbar" style="display: flex; justify-content: center;">
                <div class="btn-group">
                    <a id="NF-add-disease" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_disease_add()">
                        <i class="fa fa-plus"></i>病害录入添加
                    </a>
                </div>
            </div>
        </div>
    </div>
</form>
